#coding=utf-8
__author__ = 'czq'
def VisitBbsClass(user,bbsClass):
    if user.is_superuser==1:
        return True
    if bbsClass.visitPerm!=None:
        #user=request.user
        for u in bbsClass.visitPerm.allowUsers.all():
            if u==user:
                return True
        try:
          myRole=user.groups.all()[0]
          for role in bbsClass.visitPerm.allowRoles.all():
            if myRole==role:
                return True
        except:
            pass
        if bbsClass.visitPerm.needMoney!=None:
            if user.get_profile().extcredits1>=bbsClass.visitPerm.needMoney:
                return True
        if bbsClass.visitPerm.needExpr!=None:
            if user.get_profile().extcredits2>=bbsClass.visitPerm.needExpr:
                return True
            #raise Exception,role
        return False
    else:
        return True